<%@ Page Language="VB" StylesheetTheme="default" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Questionnaire.aspx.vb" Inherits="Modules_Questionnaires_Management_Questionnaire" title="Questionnaire Editor Page" %>
<%@ Register Assembly="DotNetPM.Web.UI.WebControls" TagPrefix="cc" Namespace="DotNetPM.Web.UI.WebControls" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
  <table id="Table2" cellpadding="2" cellspacing="2" width="100%">
        <tr>
            <td colspan="3">
                <strong><font size="2">
                    <asp:Label ID="lblHeader" runat="server" Text="QUESTIONNAIRE CREATOR"></asp:Label></font></strong>
            </td>
            <td align="right" colspan="1">
                <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="QuestionnaireManager.aspx" ForeColor="Blue" >Back</asp:HyperLink></td>
        </tr>
        <tr>
            <td colspan="4" valign="top">
                <hr size="1" width="100%" /><br /></td>
        </tr>
        <tr>
            <td rowspan="1" valign="top" width="15" height="400">
                &nbsp;</td>
            <td valign="top">
                <asp:DetailsView ID="dvQuestionnaire" runat="server" AutoGenerateRows="False" DataKeyNames="ID"
                    DataSourceID="QuestionnairesDS" Height="50px" Width="800px" EmptyDataText="Empty">
                    <Fields>
                        <asp:BoundField DataField="ID" HeaderText="ID :" InsertVisible="False" ReadOnly="True"
                            SortExpression="ID" />
                        <asp:TemplateField HeaderText="StudyID :" SortExpression="StudyID">
                            <EditItemTemplate>
                                <asp:DropDownList ID="ddlStudyID" runat="server" DataSourceID="StudyIDsDS" DataTextField="StudyID"
                                    DataValueField="StudyID" Visible=false AppendDataBoundItems=true>
                                    <asp:ListItem Text="" Value=""></asp:ListItem>
                                </asp:DropDownList>
                                <asp:TextBox ID="tbStudyID" runat="server" Text='<%# Bind("StudyID") %>' MaxLength=15/>
                                <asp:Button ID="butSwitch" runat="server" CausesValidation="False" Text="Switch to Existing List" OnClick="butSwitch_Click" />
                                <asp:RequiredFieldValidator ID="reqStudyID" runat="server" ControlToValidate="tbStudyID" 
                                    ErrorMessage="StudyID is a required field." Text="*"></asp:RequiredFieldValidator>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblStudyID" runat="server" Text='<%# Bind("StudyID") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Visit Number :" SortExpression="VisitNumber">
                            <EditItemTemplate >
                                <table>
                                <tr>
                                    <td>
                                        <asp:RadioButtonList ID="rblVisitNumber" runat="server" 
                                        RepeatDirection="Horizontal" SelectedValue='<%# Eval("VisitNumber") %>'>
                                            <asp:ListItem>1</asp:ListItem>
                                            <asp:ListItem>2</asp:ListItem>
                                            <asp:ListItem>3</asp:ListItem>
                                            <asp:ListItem>4</asp:ListItem>
                                            <asp:ListItem>5</asp:ListItem>
                                            <asp:ListItem>6</asp:ListItem>
                                            <asp:ListItem>7</asp:ListItem>
                                            <asp:ListItem>8</asp:ListItem>
                                            <asp:ListItem>9</asp:ListItem>
                                            <asp:ListItem>10</asp:ListItem>
                                            <asp:ListItem>11</asp:ListItem>
                                            <asp:ListItem>12</asp:ListItem>
                                            <asp:ListItem>13</asp:ListItem>
                                            <asp:ListItem>14</asp:ListItem>
                                            <asp:ListItem>15</asp:ListItem>
                                            <asp:ListItem>16</asp:ListItem>
                                        </asp:RadioButtonList>
                                    </td>
                                    <td>
                                        <asp:RequiredFieldValidator ID="reqVisitNumber" runat="server" ControlToValidate="rblVisitNumber" 
                                            ErrorMessage="VisitNumber is a required field." Text="*"></asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                </table>
                            </EditItemTemplate >
                            <InsertItemTemplate>
                                <table>
                                <tr>
                                    <td>
                                        <asp:RadioButtonList ID="rblVisitNumber" runat="server" 
                                        RepeatDirection="Horizontal">
                                            <asp:ListItem>1</asp:ListItem>
                                            <asp:ListItem>2</asp:ListItem>
                                            <asp:ListItem>3</asp:ListItem>
                                            <asp:ListItem>4</asp:ListItem>
                                            <asp:ListItem>5</asp:ListItem>
                                            <asp:ListItem>6</asp:ListItem>
                                            <asp:ListItem>7</asp:ListItem>
                                            <asp:ListItem>8</asp:ListItem>
                                            <asp:ListItem>9</asp:ListItem>
                                            <asp:ListItem>10</asp:ListItem>
                                            <asp:ListItem>11</asp:ListItem>
                                            <asp:ListItem>12</asp:ListItem>
                                            <asp:ListItem>13</asp:ListItem>
                                            <asp:ListItem>14</asp:ListItem>
                                            <asp:ListItem>15</asp:ListItem>
                                            <asp:ListItem>16</asp:ListItem>
                                        </asp:RadioButtonList>
                                    </td>
                                    <td>
                                        <asp:RequiredFieldValidator ID="reqVisitNumber" runat="server" ControlToValidate="rblVisitNumber" 
                                            ErrorMessage="VisitNumber is a required field." Text="*"></asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                </table>
                            </InsertItemTemplate>                            
                            <ItemTemplate>
                                        <asp:Label ID="lblVisitNumber" runat="server" Text='<%# Bind("VisitNumber") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="InstrumentID :" SortExpression="InstrumentID">
                            <InsertItemTemplate>
                                <asp:DropDownList ID="ddlInstrumentID" runat="server" DataSourceID="InstrumentIDsDS" 
                                DataTextField="Text" DataValueField="InstrumentID" AppendDataBoundItems=True >
                                    <asp:ListItem></asp:ListItem>
                                </asp:DropDownList>
                                <asp:RequiredFieldValidator ID="reqInstrumentID" runat="server" ControlToValidate="ddlInstrumentID" 
                                    ErrorMessage="InstrumentID is a required field." Text="*"></asp:RequiredFieldValidator>
                            </InsertItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblInstrumentID" runat="server" Text='<%# Bind("InstrumentID") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:DropDownList ID="ddlInstrumentID" runat="server" DataSourceID="InstrumentIDsDS" 
                                DataTextField="Text" DataValueField="InstrumentID" AppendDataBoundItems=True 
                                SelectedValue='<%# Bind("InstrumentID") %>'>
                                    <asp:ListItem></asp:ListItem>
                                </asp:DropDownList>
                                <asp:RequiredFieldValidator ID="reqInstrumentID" runat="server" ControlToValidate="ddlInstrumentID" 
                                    ErrorMessage="InstrumentID is a required field." Text="*"></asp:RequiredFieldValidator><span style="font-weight:normal">(only LOCKED Instruments)</span>

                            </EditItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Description :" SortExpression="Description">
                            <EditItemTemplate>
                                <cc:CountTextBox id="txtQuestion" runat=server TextMode="MultiLine" Text='<%# Bind("Description") %>' 
                                Width="560px" Rows="8" MaxLength="1000" />
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label4" runat="server" Text='<%# Bind("Description") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="EdtingPermission :" SortExpression="EdtingPermission" InsertVisible="False">
                            <EditItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Eval("EdtingPermission") %>'></asp:Label>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label5" runat="server" Text='<%# Bind("EdtingPermission") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="TakingPermission :" SortExpression="TakingPermission" InsertVisible="False">
                            <EditItemTemplate>
                                <asp:Label ID="Label2" runat="server" Text='<%# Eval("TakingPermission") %>'></asp:Label>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label6" runat="server" Text='<%# Bind("TakingPermission") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="CreatedDate" HeaderText="CreatedDate :" ReadOnly="True"
                            SortExpression="CreatedDate" InsertVisible="False" />
                        <asp:BoundField DataField="CreatedBy" HeaderText="CreatedBy :" ReadOnly="True" SortExpression="CreatedBy" InsertVisible="False" />
                        <asp:BoundField DataField="LastUpdated" HeaderText="LastUpdated :" ReadOnly="True"
                            SortExpression="LastUpdated" InsertVisible="False" />
                        <asp:BoundField DataField="LastUpdatedBy" HeaderText="LastUpdatedBy :" ReadOnly="True"
                            SortExpression="LastUpdatedBy" InsertVisible="False" />
                        <asp:TemplateField ShowHeader="False" Visible="False" InsertVisible="False">
                            <EditItemTemplate>
                                <asp:LinkButton ID="lbUpdate" runat="server" CausesValidation="True" CommandName="Update"
                                    ForeColor="WhiteSmoke" Font-Bold=false Text="Update" OnClick="lbUpdate_Click"></asp:LinkButton>
                                <asp:LinkButton ID="lbCancel" runat="server" CausesValidation="False" CommandName="cmdCancel"
                                    ForeColor="WhiteSmoke" Font-Bold=false Text="Cancel"></asp:LinkButton>
                            </EditItemTemplate>
                            <ItemStyle BackColor="DimGray" ForeColor="WhiteSmoke" HorizontalAlign="Right" />
                        </asp:TemplateField>
                        <asp:TemplateField ShowHeader="False" Visible=False>
                            <EditItemTemplate>
                                <asp:LinkButton ID="lbInsert" runat="server" CausesValidation="True" CommandName="Insert"
                                    ForeColor="WhiteSmoke" Font-Bold=false Text="Insert" OnClick="lbUpdate_Click"></asp:LinkButton>
                                <asp:LinkButton ID="lbCancel2" runat="server" CausesValidation="False" CommandName="cmdCancel"
                                    ForeColor="WhiteSmoke" Font-Bold=false Text="Cancel"></asp:LinkButton>
                            </EditItemTemplate>
                            <ItemStyle BackColor="DimGray" ForeColor="WhiteSmoke" HorizontalAlign="Right" />
                        </asp:TemplateField>
                        <asp:TemplateField ShowHeader="False" Visible="False" InsertVisible="False">
                            <ItemTemplate>
                                <asp:LinkButton ID="lbEdit" runat="server" CausesValidation="False" CommandName="Edit"
                                    ForeColor="WhiteSmoke" Font-Bold=false Text="Edit"></asp:LinkButton>
                                <asp:LinkButton ID="lbBack" runat="server" CausesValidation="False" CommandName="cmdCancel"
                                    ForeColor="WhiteSmoke" Font-Bold=false Text="Back"></asp:LinkButton>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:LinkButton ID="lbUpdate4" runat="server" CausesValidation="True" CommandName="Update"
                                    ForeColor="WhiteSmoke" Font-Bold=false Text="Update"></asp:LinkButton>
                                <asp:LinkButton ID="lbCancel4" runat="server" CausesValidation="False" CommandName="Cancel"
                                    ForeColor="WhiteSmoke" Font-Bold=false Text="Cancel"></asp:LinkButton>
                            </EditItemTemplate>
                            <ItemStyle BackColor="DimGray" ForeColor="WhiteSmoke" HorizontalAlign="Right" />
                        </asp:TemplateField>
                    </Fields>
                    <FieldHeaderStyle HorizontalAlign="Right" />
                </asp:DetailsView>
                <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
                <asp:ObjectDataSource ID="QuestionnairesDS" runat="server" OldValuesParameterFormatString="original_{0}"
                    SelectMethod="GetQuestionnaire" TypeName="DotNetPM.Business.Questionnaire.QuestionnaireODS" InsertMethod="CreateQuestionnaire" UpdateMethod="UpdateQuestionnaire">
                    <SelectParameters>
                        <asp:SessionParameter Name="questionnaireId" SessionField="questionnaire_questionnaireId"
                            Type="Int32" />
                    </SelectParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="id" Type="Int32" />
                        <asp:Parameter Name="studyId" Type="String" />
                        <asp:Parameter Name="visitNumber" Type="Byte" />
                        <asp:Parameter Name="instrumentId" Type="String" />
                        <asp:Parameter Name="description" Type="String" />
                        <asp:Parameter Name="original_id" Type="Int32" />
                    </UpdateParameters>
                    <InsertParameters>
                        <asp:Parameter Name="studyId" Type="String" />
                        <asp:Parameter Name="visitNumber" Type="Byte" />
                        <asp:Parameter Name="instrumentId" Type="String" />
                        <asp:Parameter Name="description" Type="String" />
                    </InsertParameters>
                </asp:ObjectDataSource>
                <asp:ObjectDataSource ID="InstrumentIDsDS" runat="server" 
                    OldValuesParameterFormatString="original_{0}" 
                    SelectMethod="GetInstrumentIDsDDL" 
                    TypeName="DotNetPM.Business.Questionnaire.QuestionnaireODS" />
                <asp:ObjectDataSource ID="StudyIDsDS" runat="server" 
                    OldValuesParameterFormatString="original_{0}" 
                    SelectMethod="GetStudyIDsDDL" 
                    TypeName="DotNetPM.Business.Questionnaire.QuestionnaireODS" />
            </td>
            
            <td colspan="2"  valign="top">
                &nbsp;
            </td>
        </tr>
    </table>
</asp:Content>

